package com.swift.utils;

import java.util.Comparator;

import org.xutils.db.table.DbModel;


public class DbModelComparator implements Comparator<DbModel> {

	private String mSortField;
	private boolean mIsNumber;
	
	public DbModelComparator(String sortField, boolean isNumber) {
		mSortField = sortField;
		mIsNumber = isNumber;
	}
	@Override
	public int compare(DbModel lhs, DbModel rhs) {
		String lhsValue = lhs.getString(mSortField) ;
		String rhsValue = rhs.getString(mSortField) ;
		if (!mIsNumber){
			return lhsValue.compareTo(rhsValue);
		}else{
			float lhsNumber = SysUtils.parseFloat(lhsValue);
			float rhsNumber = SysUtils.parseFloat(rhsValue);
			return Float.compare(lhsNumber, rhsNumber);
		}
	}  
    
};  